package lc_1686_石子游戏_VI;

import java.util.Arrays;

public class Solution {
    public int stoneGameVI(int[] aliceValues, int[] bobValues) {
        int n = aliceValues.length;
        Integer[] idx = new Integer[n];
        for (int i = 0; i < n; i++) {
            idx[i] = i;
        }
        Arrays.sort(idx, (i, j) -> aliceValues[j] + bobValues[j] - aliceValues[i] - bobValues[i]);
        int alice = 0, bob = 0;
        for (int i = 0; i < n; i++) {
            if ((i & 1) == 0) {
                alice += aliceValues[idx[i]];
            } else {
                bob += bobValues[idx[i]];
            }
        }
        return Integer.compare(alice, bob);
    }

}